﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SadlandVillage.Core;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace SadlandVillage.Minigames.Club
{
    public class ClubGame : MiniGame
    {
        Vector2 TablePosition = Vector2.Zero;
        Texture2D DjTable;
        
        ClubGameCinematic cinematic;
        Texture2D Background;
        
        bool showCinematic = true;

        public ClubGame(ContentManager content, 
            SpriteBatch spriteBatch) 
            : base(content, spriteBatch)
        {            
            cinematic = new ClubGameCinematic(content, spriteBatch);
            cinematic.CinematicOver += new ExitSceneEventHandler(cinematic_CinematicOver);
        }

        void cinematic_CinematicOver()
        {
            showCinematic = false;
        }

       

        public override void LoadContent()
        {
            DjTable = content.Load<Texture2D>(@"Minigames\Club\djtable-bg");
            Background = content.Load<Texture2D>(@"Minigames\Club\game-bg");
            
            cinematic.LoadContent();
            
        }

        public override void UnloadContent()
        {
            //Lógica de Unload aqui...
        }

        public override void Update(GameTime gameTime)
        {
            if (showCinematic)
            {
                cinematic.Update(gameTime);
            }   

            if (Input.KeyPressed(Keys.Escape))
            {
                //Dispara o evento de Cancelamento
                if (this.GameCancelled != null)
                {
                    this.GameCancelled(0);
                }
            }            
        }



        public override void Draw(GameTime gameTime)
        {
            spriteBatch.Begin();
            spriteBatch.Draw(Background, Vector2.Zero, Color.White);
            spriteBatch.Draw(DjTable, TablePosition, Color.White);            
            spriteBatch.End();

            if (showCinematic)
            {
                cinematic.Draw(gameTime);
            }
        }

        public override event BackToMapEventHandler GameCancelled;        
    }
}
